package castorss.src;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import android.text.format.DateFormat;

import com.google.code.rome.android.repackaged.com.sun.syndication.feed.synd.SyndEntry;
import com.google.code.rome.android.repackaged.com.sun.syndication.feed.synd.SyndFeed;

/**
 * Contains data from a feed entry.
 */
public class Entry
{

	/*
	 * ENTRIES_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " 
+ ENTRIES_NAME + " TEXT NOT NULL"
+ ENTRIES_CONTENT + "TEXT NOT NULL"
+ ENTRIES_AUTHOR + "TEXT NOT NULL " 
+ ENTRIES_DATE + "TEXT" // YYYY-MM-DD HH:MM:SS.SSS
+ ENTRIES_CATEGORYID + "INTEGER"
+ ENTRIES_IMG+ "BLOB"
		
+ ENTRIES_READ + " INTEGER );";
	 * 
	 */
	
	private int id;
	private String title;
	private String author;
	private String content;
	private int category;
	private String date;
	private String img;	
	private int read; //O non lu, 1 lu 
	
	/**
	 * Constructor
	 */
	public Entry(int id_, String name_, String author_, String content_, int category_, String date_, int read_)
	{
		id = id_;
		title = name_;
		author = author_;
		content = content_;
		category = category_;
		date = date_;
		read = read_;
	}
	
	public int getId() 
	{
		return id;
	}

	public void setId(int id) 
	{
		this.id = id;
	}
	
	public String getTitle()
	{
		return title;
	}
	
	public void setTitle(String name_)
	{
		title = name_;
	}
	
	public void setCategory(int category) 
	{
		this.category = category;
	}

	public int getCategory() 
	{
		return category;
	}

	
	public void setAuthor(String author) 
	{
		this.author = author;
	}

	public String getAuthor() 
	{
		return author;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getContent() {
		return content;
	}

	public void setDate(String date) {
		this.date = date;
	}

	public String getDate() {
		return date;
	}
	
	/**
	 * Transforms storage string formatted date to display string formatted date. 
	 * @return display formatted date
	 */
	public String getFormattedStringDate()
	{
		String s = "";
		Date d = getFormattedDate();
		Calendar c = Calendar.getInstance();
		c.setTime(d);
		s = c.get(Calendar.DAY_OF_MONTH)+"/"
			+c.get(Calendar.MONTH)+"/"
			+c.get(Calendar.YEAR)+" "
			+c.get(Calendar.HOUR_OF_DAY)+":"
			+c.get(Calendar.MINUTE);
		return s;
	}
	
	/**
	 * Transforms storage string formatted date to formatted date. 
	 * @return formatted date
	 */
	public Date getFormattedDate()
	{
		SimpleDateFormat df = new SimpleDateFormat("EEE MMM dd HH:mm:ss 'GMT+01:00' yyyy");
		Date d = null;
		try
		{
			d = df.parse(date);
		}
		catch (Exception e)
		{
			System.out.println(e);
		}
		return d;
	}
	

	public void setImg(String img) {
		this.img = img;
	}

	public String getImg() {
		return img;
	}
	
	public String getStringRead()
	{
		if (read == 0)
		{
			return "Non lu";
		}
		else
		{
			return "";
		}
	}
	public int getRead() {
		return read;
	}

	public void setRead(int read) {
		this.read = read;
	}
	
	@Override
	public String toString()
	{
		String s;
		s = "name : "+title+", author : "+author+", content : "+content+", category : "+category+", date : "+date.toString()+", img : "+img;
		return s;
	}
}
